<?php
/**
* Save real Estate
* @author trungdt
* @since Jul 4, 2011
* 
* Change logs
* 
*/

if (!defined('EXPONENT')) exit('');

$bds = null;
if (isset($_POST['id'])) {
	$bds = $db->selectObject('bds','id='.intval($_POST['id']));
	if ($bds) {
		$loc = unserialize($bds->location_data);
	}
} 

///if (exponent_permissions_check('administrate',$loc) || ($bds && exponent_permissions_check('edit',$loc)) || (!$bds && exponent_permissions_check('create',$loc))) {
if (exponent_users_isLoggedIn()){ // just logged in is enought
	$bds = bds_bds::update($_POST,$bds, $loc);
	$bds->location_data = serialize($loc);
    
	if (isset($bds->id)) {
		$db->updateObject($bds,'bds');
	} else {
		$bds->id=$db->insertObject($bds,'bds');
	}
	
    $ret=null;
    $ret->id=$bds->id;
    
    $params=array();
    $params['module']="bdsmodule";
    $params['action']="my_rs";
    $params['src']=$loc->src;
    $ret->url=exponent_core_makeLink($params);
    
    echo json_encode($ret);
    // done :)
    //exponent_flow_redirect();
    
} else {
	echo ""; // nothing to return. Just return empty string
}

?>